{include file="admin@public/header"/}

<style>
	#matchCon {
		width: 160px;
	}
	.url-box {
		padding: 5px 10px;
		line-height: 26px;
		cursor: pointer;
	}
	.url-box a {
		margin-right: 5px;
	}
	.ui-droplist-wrap .list-item:hover{background-color: #faffd1;}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="matchCon" class="ui-input ui-input-ph" placeholder="请输入单据号或备注" style="width: 190px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
			<i>-</i>
			<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
		</li>
		<li id="store" style="display: list-item;">
			<label>付款账户:</label>
			<span id="acctPay">
				<span class="ui-combo-wrap ui-combo-active" style="width: 118px;">
					<input type="text" class="input-txt" autocomplete="off" readonly="readonly" style="cursor: default; width: 92px;" value="" id="acctPayTitle">
					<span class="trigger"></span>
				</span>
			</span>

			<!-- 选择付款账户弹窗 -->
			<div class="ui-droplist-wrap" id="acctPayBox" style="position: absolute; z-index: 1000; display: none;">
				<div class="droplist" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
					<div class="list-item" data-value="0" id="0" title="全部">全部</div>
					{volist name="acc" id="vo"}
						<div class="list-item" data-value="{$vo.id}" id="{$vo.id}" title="{$vo.sn} {$vo.name}">{$vo.sn} {$vo.name}</div>
					{/volist}
				</div>
			</div>
		</li>
		<li id="store" style="display: list-item;">
			<label>收款账户:</label>
			<span id="acctRec">
				<span class="ui-combo-wrap ui-combo-active" style="width: 118px;">
					<input type="text" class="input-txt" autocomplete="off" readonly="readonly" style="cursor: default; width: 92px;" value="" id="acctRecTitle">
					<span class="trigger"></span>
				</span>
			</span>

			<!-- 选择收款账户弹窗 -->
			<div class="ui-droplist-wrap" id="acctRecBox" style="position: absolute; z-index: 1000; display: none;">
				<div class="droplist" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
					<div class="list-item" data-value="0" title="全部">全部</div>
					{volist name="acc" id="vo"}
						<div class="list-item" data-value="{$vo.id}" id="{$vo.id}" title="{$vo.sn} {$vo.name}">{$vo.sn} {$vo.name}</div>
					{/volist}
				</div>
			</div>
		</li>
		<li><a class="mrb more ui-btn" id="moreCon" onclick="heightSearc('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','815px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
		<!-- <li class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5704" target="_blank" class="video-icon"></a>购货订单查询</li> -->
	</ul>



</div>
<div class="wrapper btc">
	<div class="bill-ser-botm cf">
		<div class="ui-config-box">
			<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
		</div>
		<div class="fr">
			<a class="ui-btn-bill ui-btn-add" id="add"  tabid="money" data-right="ZJZZ_ADD" tabTxt="资金转账单" parentOpen="true" rel="pageTab" _href="/money/fundtf/add.html">新增</a>

			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 14px;" href="#" id="shenhe">审核<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 55px;padding: 6px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
					<li><a href="#" id="reshenhe">反审核</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
			<a class="ui-btn-bill ui-btn-hl menu-btn mrb" href="#" id="print" target="_blank">打印<b></b></a>
			<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
				<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
				<li style="padding-left: 8px;"><a href="#" id="printSet">设置</a></li>
				</ul>
			</div>
			</div>
			<a class="ui-btn-bill ui-btn-hl ml10" id="export">导出</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-batchDel">删除</a>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>

<div style="display:none;">
	<input type="hidden" name="" value="" id="acctRecId">
	<input type="hidden" name="" value="" id="acct">
</div>


<script type="text/javascript">
	$("#export").click(function (){
		var rowData = $("#grid").getRowData();
	    var rowid = '';
	    rowData.forEach(function(a,b,c){
	    	rowid += a['id']+' ';
	    })
	    console.log(rowid);
		window.location.href = '/money/Fundtf/export?rowid='+rowid;
	})
	//$(function(){
	$(document).ready(function () {

        // 获取当前日期
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth() + 1; //获取当前月
        var date = myDate.getDate(); //获取当前日
        console.log(year + '-' + mon + '-' + date)
        if (mon < 10) {
        mon = "0" + mon;
        }
        if (date < 10) {
        date = "0" + date;
        }
        $("#startdate").val(year + '-' + mon + '-01');
        $("#enddate").val(year + '-' + mon + '-' + date);

		// 跳转打开新标签页
		$("#add").click(function () {
			var tabid = $(this).attr('tabid');
			var tabTxt = $(this).attr('tabTxt');
			var _href = $(this).attr('_href');
			parent.tab.addTabItem({
				tabid: tabid,
				text: tabTxt,
				url: _href
			})
		})
		//alert("1111");
		$("#grid").jqGrid({
			url: '/money/fundtf/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			colNames: [ "ID", "操作","单据日期", "单据编号", "转出账户", "转入账户","金额","合计金额	","制单人","审核单人", "备注"],
			colModel: [
                { name: 'id',hidden:true },
				{ name: 'actions', width: 80, formatter: actions,align:'center', lable:"操作"},
				{ name: '',width: 100,align:'center', lable:"单据日期",formatter:ti},
				{ name: 'bill',width: 120,align:'center' ,lable:"单据编号"},
				{ name: '', width: 100,align:'center', lable:"转出账户",formatter:out},
				{ name: 'account_name_in',width: 200,align:'center', lable:"转入账户",formatter:enter},
				{ name: 'money',width: 200,align:'center', lable:"金额", formatter:money},
				{ name: 'son.0.total',width: 100,align:'center', lable:"合计金额"},
				{ name: 'preparer',width: 80,align:'center', lable:"制单人" },
				{ name: 'reviewer',width: 80,align:'center', lable:"审核单人"},
				{ name: 'son.0.remarks',width: 200,align:'center', lable:"备注" },
			],
			sortable: true,  //排序
		
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
            
            multiselect:true,//自带多选
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			//双击表格行事件
            ondblClickRow: function(row){
                var rowData = $('#grid').jqGrid('getRowData',row);
            	// console.log(row);
                // console.log(rowData.id);
                //var start_date = $('input[name=start_date]').val();
                //var end_date = $('input[name=end_date]').val();
                parent.tab.addTabItem({
                    tabid: "money_fundtf_add",
                    text: "资金转账单",
                    url:"/money/fundtf/edit.html?order_id="+rowData.id,
                })
                   
            }
		});
	});
	//单据日期
	function ti(cellvalue, options, rowObject) {
		var arr=rowObject.son;
		var str='';
		for(var i = 0 ; i < arr.length ; i++){
			element = arr[i];	
			str = element.time;
			var data=new Date(str * 1000);
			var y=data.getFullYear();
			var m=data.getMonth()+1;
			var d=data.getDate();
			var ste=y+'-'+m+'-'+d;
			return ste;
		}
		// var data=new Date(str * 1000);
		// var y=data.getFullYear();
		// var m=data.getMonth()+1;
		// var d=data.getDate();
		// var ste=y+'-'+m+'-'+d;
		// return ste;
	}
	//工具栏
	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="addPage(\'/money/fundtf/edit.html?order_id=' + rowObject.id + '\',\'money_fundtf_add\',\'资金转账单\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="order_del(' + rowObject.id + ')">删除</span></div>';
	}
	//合计
	function total(cellvalue, options, rowObject) {
		var arr=rowObject.son[0];
		var str=arr.total;
		return str;
	}
	//金额
	function money(cellvalue, options, rowObject) {
		var arr=rowObject.son;
		var str = '';
		for (let index = 0; index < arr.length; index++) {
			const element = arr[index];
			// switch (element.money){
			// 	case 1: element.money='现金';break
			// 	case 2: element.money='银行存款';break
			// 	default:element.money='没有找到';break
			// };
			if(index==0){
				str += element.money+'</span>';
			}else{
				str += '<p class="line"></p><span>'+element.money+'</span>';	
			}
		}
		return str;
	}
	//转入账户
	function enter(cellvalue, options, rowObject) {
		var arr=rowObject.son;
		var str = '';
		for (let index = 0; index < arr.length; index++) {
			const element = arr[index];
			// switch (element.account_name_in){
			// 	case 1: element.account_name_in='现金';break
			// 	case 2: element.account_name_in='银行存款';break
			// 	default:element.account_name_in='没有找到';break
			// };
			if(index==0){
				str += element.account_name_in+'</span>';
			}else{
				str += '<p class="line"></p><span>'+element.account_name_in+'</span>';	
			}
		}
		return str;
	}
	//转出账户
	function out(cellvalue, options, rowObject) {
		var arr=rowObject.son;
		var str = '';
		for (let index = 0; index < arr.length; index++) {
			// switch (element.account_name){
			// 	case 1: element.account_name='现金';break
			// 	case 2: element.account_name='银行存款';break
			// 	default:element.account_name='没有找到';break
			// };
			const element = arr[index];
			if(index==0){
				str += element.account_name+'</span>';
			}else{
				str += '<p class="line"></p><span>'+element.account_name+'</span>';	
			}
		}
		return str;
	}
	 //获取表格选中数据
    function selectdata(){
        var rowid=$("#grid").jqGrid("getGridParam","selarrrow");
        var rowData=jQuery("#grid").jqGrid("getRowData",rowid);
        // console.log(rowData);
        var arr = new Array();
        arr['id'] = rowid;
        arr['data'] = rowData;
        return arr;
    }

    // 删除按钮
	$("#del").click(function () {
		var xz = selectdata();
		if(xz['id']==null){
			layer.msg("请选中要删除的数据");
			return false;
		}
        order_del(xz['id']);

	})
	 // 删除方法
	function order_del($id){
		 layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
            	url: '{:url("del")}?id=' + $id,
                beforeSend: function () {
                   load = layer.load(1);
                },
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg('已删除!', {time: 1000});
                        var rowid = $("#grid").getGridParam("selrow");
      					$("#grid").delRowData(rowid);
                    } else {
                        layer.msg(data.msg, {time: 1000});
                    }
                }
            }).always(function () {
                layer.close(load);
            });
        });

	}

	// 审核按钮
	$("#shenhe").click(function () {
		var xz = selectdata();
		console.log(xz);
		if(xz['id']==null){
			layer.msg("请先选中要操作的数据");
			return false;
		}
        order_shenhe(xz['id'],1);	
	})
	// 反审核按钮
	$("#reshenhe").click(function () {
		var xz = selectdata();
		if(xz['id']==null){
			layer.msg("请先选中要操作的数据");
			return false;
		}
        order_shenhe(xz['id'],2);
	})
	 // 审核方法--0,审核 1，反审核
	function order_shenhe($id,$type){
        $.ajax({
        	url: '{:url("shenhe")}?id=' + $id +'&type=' +$type,
            beforeSend: function () {
                load = layer.load(1);
            },
            success: function (data) {
            	if (data.code == 1) {
                	layer.msg(data.msg, {time: 1000});
                	
                    $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                } else {
                    layer.msg(data.msg, {time: 1000});
                }
            }
            
        }).always(function () {
            layer.close(load);
        });
	}
	//多选删除
	$("#btn-batchDel").click(function(){
		var ids = $("#grid").jqGrid('getGridParam','selarrrow');
		var del=1;
		$.ajax({
			daty:"post",
			url:"del",
			datatype:"json",
			data:{
				ids:ids,
				del:del
			},
			success:function(data){
				if (data.code==1) {
					layer.msg('删除成功');
					for (var i = 0, l = ids.length; i < l; i++) {
						$("#grid").jqGrid("delRowData", ids[0]);
					}
				}else{
					layer.msg('删除失败');

				}
			},
			error:function(da){
				layer.msg('请求失败');
			}
		})
	})

</script>

<script>
	$(document).ready(function () {
		// 搜索付款账户弹窗
		$("#acctPay").on("click",function(){
			var top = $(this).offset().top;
			var left = $(this).offset().left;
			var width = $(this).width();
			$("#acctPayBox").toggle();
			$("#acctPayBox").css({ "top": (top + 24) + "px", "left": (left) + "px", "minWidth": width + "px" });
		});
		// 选择付款账户
		$("#acctPayBox .list-item").on("click",function(){
			$(this).addClass("selected").siblings().removeClass("selected");
			var title=$(this).attr("title");
			var val=$(this).attr("data-value");
			$("#acctPayTitle").val(title);
			$("#acct").val(val);
			$("#acctPayBox").hide();
		});
	})
	//付款账户弹窗框外点击则隐藏
	$(document).mouseup(function (e) {
		if(e.target.id!="acctPay"){
			var con = $("#acctPayBox");   // 设置目标区域
			if (!con.is(e.target) && con.has(e.target).length === 0) {
				$("#acctPayBox").hide();
			}
		} 
	});



	$(document).ready(function () {
		// 搜索收款账户弹窗
		$("#acctRec").on("click",function(){
			var top = $(this).offset().top;
			var left = $(this).offset().left;
			var width = $(this).width();
			$("#acctRecBox").toggle();
			$("#acctRecBox").css({ "top": (top + 24) + "px", "left": (left) + "px", "minWidth": width + "px" });
		});
		// 选择收款账户
		$("#acctRecBox .list-item").on("click",function(){
			$(this).addClass("selected").siblings().removeClass("selected");
			var title=$(this).attr("title");
			var val=$(this).attr("data-value");
			$("#acctRecId").val(val);
			$("#acctRecTitle").val(title);
			$("#acctRecBox").hide();
		});
	})
	//收款账户弹窗框外点击则隐藏
	$(document).mouseup(function (e) {
		if(e.target.id!="acctRec"){
			var con = $("#acctRecBox");   // 设置目标区域
			if (!con.is(e.target) && con.has(e.target).length === 0) {
				$("#acctRecBox").hide();
			}
		} 
	});
	//搜索
	$("#search").click(function (){
		$("#grid").jqGrid('clearGridData');
		var matchcon=$("#matchCon").val();
		var startdate=$("#startdate").val();
		var enddate=$("#enddate").val();
		var acctRecId=$("#acctRecId").val();
		var acct=$("#acct").val();
		$("#grid").jqGrid('setGridParam', {
        datatype: 'json',
        postData: { 'ajax': '100', 'acctRecId':acctRecId,'acct':acct,'matchcon':matchcon,'startdate':startdate,'enddate':enddate,'search':1 }, //发送数据 
        page: 1
      }).trigger("reloadGrid"); //重新载入
		var postData = $("#grid").jqGrid("getGridParam", "postData");
	　　　　$.each(postData, function (k, v) { 
	　　　　　　delete postData[k];  
	　　　　}); 
	})
	// 高级搜索
	function heightSearc(url, title, width, height){
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			shade: 0.3,
			maxmin: true, //开启最大化最小化按钮
			btn: ['重置', '查询', '关闭'],
			area: [width, height],
			content: url,
			btn1: function (index, layero) {
				document.getElementById("layui-layer-iframe"+index).contentWindow.location.reload();
				return false;
			},
			btn2:function(index, layero){
				layer.close(index);
				var fromDate=layero.find("iframe")[0].contentWindow.$("#filter-fromDate").val();//高级搜索开始时间
				var toDate=layero.find("iframe")[0].contentWindow.$("#filter-toDate").val();//高级搜索结束时间
				var remarkCon=layero.find("iframe")[0].contentWindow.$("#remarkCon").val();//备注
				var usersCreatId=layero.find("iframe")[0].contentWindow.$("#usersCreatId").val();//制单人
				var usersModifyId=layero.find("iframe")[0].contentWindow.$("#usersModifyId").val();//最后修改人
				var payAccId=layero.find("iframe")[0].contentWindow.$("#payAccId").val();//付款账户
				var recAccId=layero.find("iframe")[0].contentWindow.$("#recAccId").val();//收款账户
				var courierNumberInput=layero.find("iframe")[0].contentWindow.$("#courierNumberInput").val();//快递单号
				var usersChecksId=layero.find("iframe")[0].contentWindow.$("#usersChecksId").val();//审核人
				var checkStatusId=layero.find("iframe")[0].contentWindow.$("#checkStatusId").val();//审核状态
				$("#grid").jqGrid('setGridParam', {
			        datatype: 'json',
			        postData: { 
			        	'ajax':'100',
			        	'searchs':'1',
						'fromDate':fromDate,
						'toDate':toDate,
						'remarkCon':remarkCon,
						'usersCreatId':usersCreatId,
						'usersModifyId':usersModifyId,
						'payAccId':payAccId,
						'recAccId':recAccId,
						'courierNumberInput':courierNumberInput,
						'usersChecksId':usersChecksId,
						'checkStatusId':checkStatusId
			        }, //发送数据 
			        page: 1
			    }).trigger("reloadGrid"); //重新载入
			    var postData = $("#grid").jqGrid("getGridParam", "postData");
			　　　　$.each(postData, function (k, v) { 
			　　　　　　delete postData[k];  
			　　　　});
				return false;
			},
			btn3:function(index, layero){
				layer.close(index);
				return false;
			},
			success: function (layero, index) {
	            //渲染按钮样式
				$(".layui-layer-btn .layui-layer-btn0").css({
					"background": "-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#f4f4f4))",
					"float": "left",
					"color":"#555",
					"border":"1px solid #c1c1c1",
				});
				$(".layui-layer-btn .layui-layer-btn1").css({
					"background": "linear-gradient(to bottom,#4dc2e6 0,#38B3EB 100%)",
					"color":"#fff",
					"border":"1px solid #38B3EB"

				});
	        }
		});
	};
</script>


{include file="admin@public/footer"/}